package com.cloudsigns.factorymanager2.engineering.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.adapter.AddPublicationOrderAdapter;
import com.cloudsigns.factorymanager2.engineering.bean.MediaBean;
import com.cloudsigns.factorymanager2.engineering.bean.PatrolOrderBean;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;
import com.cloudsigns.factorymanager2.project.utils.DateUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class PatrolOrderDetailActivity1 extends Activity implements View.OnClickListener {
    private View rl_back;
    private TextView tv_title;
    private TextView  edt_date;
    private LayoutInflater layoutInflater;
    private PatrolOrderBean patrolOrderBean;
    Map<String, List<MediaBean>> mediaBeanMap = new HashMap<>();
    private String TAG = PatrolOrderDetailActivity.class.getSimpleName();


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
            );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_patrol_order_detail1);

        layoutInflater = getLayoutInflater();
        init();
    }

    private void init() {
        rl_back = findViewById(R.id.rl_back);
        tv_title = findViewById(R.id.tv_title);
        edt_date = findViewById(R.id.edt_date);


        tv_title.setText(getResources().getText(R.string.patrol_order));
        rl_back.setOnClickListener(this);

        Intent mIntent = getIntent();
        if (null != mIntent) {
            patrolOrderBean = (PatrolOrderBean) mIntent.getSerializableExtra(ConstantUtil.KEY_2);
            initData();
        }
    }


    private void initData() {
        if (null != patrolOrderBean) {
            edt_date.setText(DateUtil.getYyyy_Mm_Dd(patrolOrderBean.getBeginDate()) + "-" + DateUtil.getYyyy_Mm_Dd(+patrolOrderBean.getCompleteDate()));


            List<MediaBean> mediaBeanList = patrolOrderBean.getMediaList();
            if (null != mediaBeanList) {
                for (MediaBean mediaBean : mediaBeanList) {
                    String areaName = mediaBean.getAreaName();
                    if (mediaBeanMap.containsKey(areaName)) {
                        mediaBeanMap.get(areaName).add(mediaBean);
                    } else {
                        List<MediaBean> tmpMediaBeanList = new ArrayList<>();
                        tmpMediaBeanList.add(mediaBean);
                        mediaBeanMap.put(areaName, tmpMediaBeanList);
                    }
                }
            }
        }
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rl_back:
                finish();
                break;
        }
    }

}
